﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;


namespace ClientApplication
{
    [DataContract]
    [Serializable]
    public class Rules
    {
        [DataMember]
        public DateTime date { get; set; }
        [DataMember]
        public string place { get; set; }
        [DataMember]
        public double height { get; set; } 
        [DataMember]
        public int amountJudges { get; set; }
        [DataMember]
        public int sex { get; set; }//0 == male, 1 == female
        //[DataMember]
        //public int maxContestants { get; private set; }

        public Rules()
        {
            date = DateTime.Now;
            place = "";
            height = 0;
            amountJudges = 0;
            sex = 0;
            //maxContestants = 0;
        }

        public Rules(double height, int amountJudges, int sex, DateTime date, string place)
        {
            this.height = height;
            this.amountJudges = amountJudges;
            this.sex = sex;
            //this.maxContestants = maxContestants;
            this.date = date;
            this.place = place;
        }

        public bool JumpCodeFormatCheck(string jumpCode)
        {
            //1. Check if the string size is correct
            if (jumpCode.Count() == 5)
            {
                char c0 = jumpCode[0];
                char c1 = jumpCode[1];
                char c2 = jumpCode[2];
                char c3 = jumpCode[3];
                char c4 = jumpCode[4];

                //2 Check if last digit is NOT a-e or A-E
                if (!((c4 == 'a' || c4 == 'b' || c4 == 'c' || c4 == 'd' || c4 == 'e') || (c4 == 'A' || c4 == 'B' || c4 == 'C' || c4 == 'D' || c4 == 'E')))
                    return false;
                //3 Check if 
                if (c0 == '0' && (c1 == '1' || c1 == '2' || c1 == '3' || c1 == '4') && (c4 != 'd' && c4 != 'D'))
                {
                    if (c3 == '0' || c3 == '1' || c3 == '2' || c3 == '3' || c3 == '4' || c3 == '5' || c3 == '6' || c3 == '7' || c3 == '8' || c3 == '9')
                    {
                        if (c2 == '0')
                        {
                            return true;
                        }
                        else if (c2 == '1' && (c4 == 'c' || c4 == 'C' || c4 == 'b' || c4 == 'B'))
                        {
                            return true;
                        }
                    }
                }
                else if (c0 == '1' && c1 == '0' && c2 == '1' && c3 == '1')
                {
                    return true;
                }
                else if ((c0 == '5' || c0 == '6') && (c1 == '1' || c1 == '2' || c1 == '3' || c1 == '4'))
                {
                    if (c2 == '0' || c2 == '1' || c2 == '2' || c2 == '3' || c2 == '4' || c2 == '5' || c2 == '6' || c2 == '7' || c2 == '8' || c2 == '9')
                    {
                        if (c3 == '0' || c3 == '1' || c3 == '2' || c3 == '3' || c3 == '4' || c3 == '5' || c3 == '6' || c3 == '7' || c3 == '8' || c3 == '9')
                        {
                            return true;
                        }
                    }
                }
                else if ((c0 == '0') && (c1 == '6'))
                {
                    if (c2 == '0' || c2 == '1' || c2 == '2' || c2 == '3' || c2 == '4')
                    {
                        if (c3 == '0' || c3 == '1' || c3 == '2' || c3 == '3' || c3 == '4' || c3 == '5' || c3 == '6' || c3 == '7' || c3 == '8' || c3 == '9')
                        {
                            return true;
                        }
                    }
                }
            }
            return false;
        }

        public void ClearRules()
        { 
            date = new DateTime();
            place = "";
            height = 0;
            amountJudges = 0;
            sex = -1; 
        }

        /// <summary>
        /// Calculating Degree of Difficulty
        /// * Returns a double-value > 0 if it is a correct code
        /// * Returns a value less than 0 if it is an incorrect code
        /// </summary>
        /// <param name="jumpCode"></param>
        /// <returns></returns>
        public double DegreeOfDifficulty(string jumpCode)
        {
            try
            {
                if (jumpCode.Count() == 4)
                {
                    jumpCode = '0' + jumpCode;
                }

                if (JumpCodeFormatCheck(jumpCode))
                {
                    jumpCode = jumpCode.ToUpper();
                    double somersaults = 0;
                    double twists = 0;
                    bool isFlying = false;
                    int group = 0;
                    char jumpPos;
                    bool armstand = false;

                    //xxxxB
                    jumpPos = jumpCode[4];
                    //ARMSTAND
                    if (jumpCode[1] == '6' || jumpCode[0] == '6')
                    {
                        armstand = true;
                    }
                    if (jumpCode[0] == '1')
                    {
                        twists = 0;
                        group = int.Parse(jumpCode[0].ToString());
                        somersaults = double.Parse(jumpCode[2].ToString() + jumpCode[3].ToString()) / 2; //Hantera 1011, tveksam till att detta blir rätt
                    }
                    else if (jumpCode[0] == '0')
                    {
                        twists = 0;
                        somersaults = double.Parse(jumpCode[3].ToString()) / 2;
                        if (jumpCode[1] == '6')
                        {
                            group = int.Parse(jumpCode[2].ToString());
                        }
                        else
                        {
                            group = int.Parse(jumpCode[1].ToString());
                            armstand = false;
                        }

                        if ((jumpPos == 'B' || jumpPos == 'C') && (jumpCode[1] != '6'))
                        {
                            if (jumpCode[2] == '1')
                                isFlying = true;
                            else
                                isFlying = false;
                        }
                    }
                    else if (jumpCode[0] == '5' || jumpCode[0] == '6')
                    {
                        group = int.Parse(jumpCode[1].ToString());
                        somersaults = double.Parse(jumpCode[2].ToString()) / 2;
                        twists = double.Parse(jumpCode[3].ToString()) / 2;
                    }

                    double difficultyReturned = CalculateA(somersaults);
                    difficultyReturned += CalculateB(somersaults, jumpPos, group, isFlying, armstand);
                    difficultyReturned += CalculateC(somersaults, twists, jumpPos, group, armstand);
                    difficultyReturned += CalculateD(somersaults, twists, jumpPos, group, armstand);
                    difficultyReturned += CalculateE(somersaults, twists, group, armstand);
                    difficultyReturned = Math.Round(difficultyReturned, 1);
                    if (difficultyReturned < 0)
                    {
                        return -10;
                    }
                    else
                    {
                        return difficultyReturned;
                    }
                }
                else
                {
                    return -10;
                }
            }
            catch
            {
                return -10;
            }
        }
        #region Calculation parts
        public double CalculateA(double somersaults)
        {
            double[,] tableA = {{ 0.9, 1.1, 1.2, 1.6, 2.0, 2.4, 2.7, 3.0, 3.3 , 3.8, -10}, //1m
                                {1.0, 1.3, 1.3, 1.5, 1.8, 2.2, 2.3, 2.8, 2.9, 3.5, -10},//3m
                                {0.9, 1.1, 1.2, 1.6, 2.0, 2.4, 2.7, 3.0, -10, -10, -10},
                                {1.0, 1.3, 1.3, 1.5, 1.8, 2.2, 2.3, 2.8, 3.5, 3.5, -10},
                                {1.0, 1.3, 1.4, 1.5, 1.9, 2.1, 2.5, 2.7, 3.5, 3.5, 4.5}};
            int row = 0;
            int column = 0;
            if (height == 1)
                row = 0;
            else if (height == 3)
                row = 1;
            else if (height == 5)
                row = 2;
            else if (height == 7.5)
                row = 3;
            else if (height == 10)
                row = 4;
            else
                return -10;

            if (somersaults == 0)
                column = 0;
            else if (somersaults == 0.5)
                column = 1;
            else if (somersaults == 1)
                column = 2;
            else if (somersaults == 1.5)
                column = 3;
            else if (somersaults == 2)
                column = 4;
            else if (somersaults == 2.5)
                column = 5;
            else if (somersaults == 3)
                column = 6;
            else if (somersaults == 3.5)
                column = 7;
            else if (somersaults == 4)
                column = 8;
            else if (somersaults == 4.5)
                column = 9;
            else if (somersaults == 5.5)
                column = 10;
            else
                return -10;

            return tableA[row, column];
        }
        public double CalculateB(double somersaults, char jumpPos, int group, bool isFlying, bool armstand)
        {
            double flyingScore = 0;
            int row = 0; //Beror av jumpPos
            int column = 0; //Beror av somersault
            int z = 0; //Beror av group

            double[, ,] tableBFor1and3 = {{{0.1, 0.1, 0.1, -0.3}, {0, 0, 0, 0.1}, {0, 0.1, 0, 0.2}, {0, 0, 0, 0.3}, {0, 0.1, 0.2, 0.4}},
                                        {{0.2, 0.2, 0.2, -0.2}, {0.1, 0.3, 0.3, 0.3}, {0.2, 0.3, 0.2, 0.5}, {0.3, 0.3, 0.3, 0.6}, {0.4, 0.4, 0.5, 0.8}},
                                        {{0.3, 0.3, 0.3, 0.1}, {0.4, 0.5, 0.6, 0.8}, {0.6, 0.7, 0.6, -10}, {-10, -10, -10, -10}, {-10, -10, -10, -10}},
                                        {{0.1, 0.1, 0.1, -0.1}, {0, -0.1, -0.1, 0.2}, {0, -0.1, -0.2, 0.4}, {0, 0, 0, -10}, {-10, -10, -10, -10}},
                                        {{0.2, 0.1, 0.1, 0.4}, {0.2, 0.2, 0.2, 0.5}, {0.3, 0.3, 0.3, 0.7}, {0.4, -10, -10, -10}, {-10, -10, -10, -10}}};

            double[, ,] tableBFor5and7and10 = {{{0.1, 0.1, 0.1, -0.3, 0.1}, {0, 0, 0, 0.1, 0}, {0, 0.1, 0, 0.2, 0.1}, {0, 0, 0, 0.3, 0.2}, {0, 0.1, 0.3, 0.4, 0.3}, {0, -10, -10, -10, -10}},
                                             {{0.2, 0.2, 0.2, -0.2, 0.3}, {0.1, 0.3, 0.3, 0.3, 0.3}, {0.2, 0.3, 0.2, 0.5, 0}, {0.3, 0.3, 0.3, 0.6, 0.4}, {0.4, 0.4, 0.6, 0.7, 0.5,}, {-10, -10, -10, -10, -10}},
                                             {{0.3, 0.3, 0.3, 0.1, 0.4}, {0.4, 0.5, 0.6, 0.8, 0.5}, {0.6, 0.7, 0.6, -10, -10}, {-10, -10, -10, -10, -10}, {-10, -10, -10, -10, -10}, {-10, -10, -10, -10, -10}},
                                             {{0.1, 0.1, 0.1, -0.1, 0}, {0, -0.1, -0.1, 0.2, 0}, {0, -0.1, -0.2, 0.4, 0}, {0, 0, 0, -10, -10}, {-10, -10, -10, -10, -10}, {-10, -10, -10, -10, -10}},
                                             {{0.2, 0.1, 0.1, 0.4, -10}, {0.2, 0.2, 0.2, 0.5, -10}, {0.3, 0.3, 0.3, 0.7, -10}, {0.4, -10, -10, -10, -10}, {-10, -10, -10, -10, -10}, {-10, -10, -10, -10, -10}}};

            //Set x
            if (jumpPos == 'A')
                row = 2;
            else if (jumpPos == 'B')
                row = 1;
            else if (jumpPos == 'C')
                row = 0;
            else if (jumpPos == 'D')
                row = 3;
            else if (jumpPos == 'E')
                row = 4;

            //Set y
            if (0 <= somersaults && somersaults <= 1)
                column = 0;
            else if (1.5 <= somersaults && somersaults <= 2)
                column = 1;
            else if (somersaults == 2.5)
                column = 2;
            else if (3 <= somersaults && somersaults <= 3.5)
                column = 3;
            else if (4 <= somersaults && somersaults <= 4.5)
                column = 4;
            else if (somersaults == 5.5)
                column = 5;

            //Set z
            if (armstand)
                z = 4;
            else
                z = group - 1;

            if ((height == 1 || height == 3) && column < 5)
            {
                if (isFlying)
                    flyingScore = tableBFor1and3[4, column, z];
                return tableBFor1and3[row, column, z] + flyingScore;
            }
            else if (height == 5 || height == 7.5 || height == 10)
            {
                if (isFlying)
                    flyingScore = tableBFor5and7and10[4, column, z];
                return tableBFor5and7and10[row, column, z] + flyingScore;
            }
            else
                return -10;
        }
        public double CalculateC(double somersaults, double twists, char jumpPos, int group, bool armstand)
        {
            int row = group-1; //Beror av group
            int column = 0; //Beror av twists och somersaults

            double[,] tableCFor1and3 = {
                                        {0.4, 0.4, 0.4, 0.4, 0.6, 0.8, 0.8, 1.0, 1.2, 1.2, 1.5, 1.6, 1.9, 2.0}, //FWD
                                        {0.2, 0.4, 0, 0, 0.4, 0.8, 0.7, 0.8, 1.2, 1.1, 1.4, 1.7, 1.8, 2.1}, //BACK
                                        {0.2, 0.4, 0, 0, 0.4, 0.8, 0.6, 0.8, 1.2, 1.0, 1.4, 1.8, 1.8, 2.1}, //REV
                                        {0.2, 0.4, 0.2, 0.4, 0.4, 0.8, 0.8, 0.8, 1.2, 1.2, 1.5, 1.6, 1.9, 2.0}//INW 
                                       };
            double[,] tableCFor5and7and10 = {
                                             {0.4, 0.4, 0.4, 0.4, 0.6, 0.8, 0.8, 1.0, 1.2, 1.2, 1.5, 1.6, 1.6, 1.9, 2.0, 2.0}, //FWD
                                             {0.2, 0.4, 0, 0, 0.4, 0.8, 0.6, 0.8, 1.2, 1.0, 1.4, 1.7, 1.5, 1.8, 2.1, 1.9}, //BACK
                                             {0.2, 0.4, 0, 0, 0.4, 0.8, 0.6, 0.8, 1.2, 1.0, 1.4, 1.7, 1.5, 1.8, 2.1, 1.9}, //REV
                                             {0.2, 0.4, 0.2, 0.4, 0.4, 0.8, 0.8, 0.8, 1.2, 1.2, 1.5, 1.6, 1.6, 1.9, 2.0, 2.0}, //INW 
                                             {0.4, 0.5, 0.5, 0.4, 1.2, 1.3, 1.3, 1.5, 1.7, 1.7, 1.9, 2.1, 2.1, 2.3, 2.5, 2.5}, //ARM FORW
                                             {0.4, 0.5, 0.5, 0.5, 1.2, 1.3, 1.3, 1.3, 1.7, 1.7, 1.9, 2.1, 2.1, 2.3, 2.5, 2.5} //ARM BACK/REV
                                            };
            //Inga twists -> inga poäng här
            if (twists == 0)
                return 0;

            //Felhantering
            if (!armstand && (jumpPos != 'A' && jumpPos != 'B' && jumpPos != 'C') && somersaults == 0.5 && twists > 0)//Dives with ½ somersault and twists can only be executed in positions A, B, or C.
                return -10;
            else if (!armstand && jumpPos != 'D' && (somersaults == 1 || somersaults == 1.5) && twists > 0)//Dives with 1 or 1½ somersaults and twists can only be executed in position D.
                return -10;
            else if (!armstand && (jumpPos != 'B' && jumpPos != 'C') && somersaults >= 2 && twists > 0)//Dives with 2 or more somersaults and twists can only be executed in positions B or C.
                return -10;
            else if (armstand && jumpPos != 'D' && (somersaults == 1 || somersaults == 1.5 || somersaults == 2) && twists >= 1)//Armstand dives with 1, 1½, or 2 somersaults and one or more twists can only be executed in position D
                return -10;
            else if (armstand && (jumpPos != 'B' && jumpPos != 'C') && (somersaults >= 2.5) && twists > 0)//Armstand dives with 2½ or more somersaults and twist can only be executed in positions B or C
                return -10;

            //Vid ARMSTÅENDE
            if (armstand)
            {
                if (group == 1)
                    row = 4;
                else if (group == 2 || group == 3)
                    row = 5;
            }

#region Handle 1, 3 (C)
            if (height == 1 || height == 3)
            {
                if (twists == 0.5)
                {
                    if (somersaults == 0.5 || somersaults == 1)
                        column = 0;
                    else if (somersaults == 1.5 || somersaults == 2)
                        column = 1;
                    else if (somersaults == 2.5)
                        column = 2;
                    else if (somersaults == 3 || somersaults == 3.5)
                        column = 3;
                }
                else if (twists == 1)
                    column = 4;
                else if (twists == 1.5)
                {
                    if (somersaults == 0.5 || somersaults == 1 || somersaults == 1.5 || somersaults == 2)
                        column = 5;
                    else if (somersaults == 2.5 || somersaults == 3 || somersaults == 3.5)
                        column = 6;
                }
                else if (twists == 2)
                    column = 7;
                else if (twists == 2.5)
                {
                    if (somersaults == 0.5 || somersaults == 1 || somersaults == 1.5 || somersaults == 2)
                        column = 8;
                    else if (somersaults == 2.5 || somersaults == 3 || somersaults == 3.5)
                        column = 9;
                }
                else if (twists == 3)
                    column = 10;
                else if (twists == 3.5)
                    column = 11;
                else if (twists == 4)
                    column = 12;
                else if (twists == 4.5)
                    column = 13;
                else
                    return -10; //Om inget av våra alternativ fullföljts så returnerar vi felkoden -10
            }
#endregion Handle 1, 3 (C)

#region Handle 5, 7.5, 10 (C)
            if (height == 5 || height == 7.5 || height == 10)
            {
                if (twists == 0.5)
                {
                    if (somersaults == 0.5 || somersaults == 1)
                        column = 0;
                    else if (somersaults == 1.5 || somersaults == 2)
                        column = 1;
                    else if (somersaults == 2.5)
                        column = 2;
                    else if (somersaults == 3 || somersaults == 3.5)
                        column = 3;
                }
                else if (twists == 1)
                    column = 4;
                else if (twists == 1.5)
                {
                    if (somersaults == 0.5 || somersaults == 1 || somersaults == 1.5 || somersaults == 2)
                        column = 5;
                    else if (somersaults == 2.5 || somersaults == 3 || somersaults == 3.5)
                        column = 6;
                }
                else if (twists == 2)
                    column = 7;
                else if (twists == 2.5)
                {
                    if (somersaults == 0.5 || somersaults == 1 || somersaults == 1.5 || somersaults == 2)
                        column = 8;
                    else if (somersaults == 2.5 || somersaults == 3 || somersaults == 3.5)
                        column = 9;
                }
                else if (twists == 3)
                    column = 10;
                else if (twists == 3.5)
                {
                    if (somersaults == 0.5 || somersaults == 1 || somersaults == 1.5 || somersaults == 2.0)
                        column = 11;
                    else if (somersaults == 2.5 || somersaults == 3 || somersaults == 3.5)
                        column = 12;
                }
                else if (twists == 4)
                    column = 13;
                else if (twists == 4.5)
                {
                    if (somersaults == 0.5 || somersaults == 1 || somersaults == 1.5 || somersaults == 2)
                        column = 14;
                    else if (somersaults == 2.5 || somersaults == 3 || somersaults == 3.5)
                        column = 15;
                }
                else
                    return -10; //Om inget av våra alternativ fullföljts så returnerar vi felkoden -10
            }
#endregion Handle 5, 7.5, 10 (C)

            if ((height == 1 || height == 3) && column < 14)
                return tableCFor1and3[row, column];
            else if (height == 5 || height == 7.5 || height == 10)
                return tableCFor5and7and10[row, column];
            else
                return -10;
        }
        public double CalculateD(double somersaults, double twists, char jumpPos, int group, bool armstand)
        {
            int row = 0; //Beror av höjd
            int column = 0; //Beror av somersaults och jumpPos
            double[,] tableDfor1and3 = {
                                        {0, 0.5, 0.2, 0.6, 0.3, 0.5, 0.6, 0.5},
                                        {0, 0.3, 0.2, 0.4, 0.3, 0.3, 0.3, 0.3}
                                       };
            double[,] tableDfor5and7and10 = {
                                             {0, 0.5, 0.2, 0.5, 0.3, 0.4, 0.6, 0.6, 0.5},
                                             {0, 0.3, 0.2, 0.3, 0.3, 0.4, 0.4, 0.3, 0.3},
                                             {0, 0.2, 0.2, 0.2, 0.3, 0.4, 0.3, 0.3, 0.2}
                                            };
            double[] tableDforArmstand = { 0.2, 0.4, 0.2, 0.4, 0.3, 0.5 };

            #region Handle 5,7.5,10 and eventual armstanding(D)
            if (height == 5 || height == 7.5 || height == 10)
            {
                #region D for Armstand(column-choosing and return)
                if (armstand)
                {
                    if (twists != 0)
                        return 0;
                    if (group == 1)
                    {
                        if (somersaults == 0 || somersaults == 0.5 || somersaults == 1 || somersaults == 1.5 || somersaults == 2)
                            column = 0;
                        if (somersaults >= 2.5)
                            column = 1;
                    }
                    else if (group == 2)
                    {
                        if (somersaults == 0 || somersaults == 0.5)
                            column = 2;
                        if (somersaults == 1 || somersaults == 1.5 || somersaults == 2 || somersaults == 2.5 || somersaults == 3 || somersaults == 3.5 || somersaults == 4)
                            column = 3;
                    }
                    else if (group == 3)
                    {
                        if (somersaults == 0 || somersaults == 0.5)
                            column = 4;
                        if (somersaults == 1 || somersaults == 1.5 || somersaults == 2 || somersaults == 2.5 || somersaults == 3 || somersaults == 3.5 || somersaults == 4)
                            column = 5;
                    }
                    return tableDforArmstand[column];
                }
                #endregion D for Armstand(column-choosing and return)
                if (height == 5)
                    row = 0;
                else if (height == 7.5)
                    row = 1;
                else if (height == 10)
                    row = 2;

                if (group == 1) //FWD
                {
                    if (somersaults == 0.5 || somersaults == 1 || somersaults == 1.5 || somersaults == 2 || somersaults == 3 || somersaults == 3.5)
                        column = 0;
                    else if (somersaults == 4 || somersaults == 4.5 || somersaults == 5 || somersaults == 5.5)
                        column = 1;
                }
                else if (group == 2) //BACK
                {
                    if (somersaults == 0.5 || somersaults == 1 || somersaults == 1.5 || somersaults == 2 || somersaults == 2.5 || somersaults == 3)
                        column = 2;
                    else if (somersaults == 3.5 || somersaults == 4 || somersaults == 4.5)
                        column = 3;
                }
                else if (group == 3) //REV
                {
                    if (somersaults == 0.5 || somersaults == 1 || somersaults == 1.5 || somersaults == 2)
                        column = 4;
                    else if (somersaults == 2.5 || somersaults == 3)
                        column = 5;
                    else if (somersaults == 3.5 || somersaults == 4 || somersaults == 4.5)
                        column = 6;
                }
                else if (group == 4) //INW
                {
                    if (somersaults == 0.5 || somersaults == 1)
                        column = 7;
                    else if (somersaults == 1.5 || somersaults == 2 || somersaults == 2.5 || somersaults == 3 || somersaults == 3.5 || somersaults == 4 || somersaults == 4.5)
                        column = 8;
                }
                return tableDfor5and7and10[row, column];
            }
            #endregion Handle 5,7.5,10 and eventual armstanding(D)
            #region Handle 1,3 (D)
            else if(height ==1 || height == 3)
            {
                if (height == 1)
                    row = 0;
                else if (height == 3)
                    row = 1;

                if (group == 1) //FWD
                {
                    if (somersaults == 0.5 || somersaults == 1 || somersaults == 1.5 || somersaults == 2 || somersaults == 2.5 || somersaults == 3 || somersaults == 3.5)
                        column = 0;
                    else if (somersaults == 4 || somersaults == 4.5)
                        column = 1;
                }
                else if (group == 2) //BACK
                {
                    if (somersaults == 0.5 || somersaults == 1 || somersaults == 1.5 || somersaults == 2 || somersaults == 2.5 || somersaults == 3)
                        column = 2;
                    else if (somersaults == 3.5 || somersaults == 4 || somersaults == 4.5)
                        column = 3;
                }
                else if (group == 3) //REV
                {
                    if (somersaults == 0.5 || somersaults == 1 || somersaults == 1.5 || somersaults == 2 || somersaults == 2.5 || somersaults == 3)
                        column = 4;
                    else if (somersaults == 3.5 || somersaults == 4 || somersaults == 4.5)
                        column = 5;
                }
                else if (group == 4) //INW
                {
                    if (somersaults == 0.5 || somersaults == 1)
                        column = 6;
                    else if (somersaults == 1.5 || somersaults == 2 || somersaults == 2.5 || somersaults == 3 || somersaults == 3.5 || somersaults == 4 || somersaults == 4.5)
                        column = 7;
                }
                return tableDfor1and3[row, column];
            }
            return -10; //Om inget annat alternativ hittills har valts så returnerar vårt egendefinierade felhanteringsvärde -10
            #endregion Handle 1,3 (D)
        }
        public double CalculateE(double somersaults, double twists, int group, bool armstand)
        {
            int row = 0;
            int column = 0;
            double[,] tableEfor1and3 = {{0, 0.1, 0, 0.2, 0, 0.2, 0, 0.2, 0},
                                        {0.1, 0, 0.2, 0, 0.3, 0, 0.4, 0, 0.4}
                                       };
            double[,] tableEfor5and7and10 = {{0, 0.1, 0, 0.2, 0, 0.2, 0, 0.0, 0, 0},
                                             {0.1, 0, 0.2, 0, 0.3, 0, 0.4, 0, 0.4, 0.0},
                                             {0, 0.1, 0, 0.2, 0, 0.2, 0, 0.3, 0, 0},
                                             {0.1, 0, 0.2, 0, 0.3, 0, 0.4, 0, 0.4, 0.0}
                                            };
            if (twists != 0)
                return 0;
            //ROW
            if (armstand)
            {
                if (group == 2 || group == 3) // BACK eller REV
                    row = 2;
                else if (group == 1)
                    row = 3;
            }
            else if (group == 1 || group == 4) // FWD eller INW
            {
                row = 0;
            }
            else if (group == 2 || group == 3) // BACK eller REV
            {
                row = 1;
            }

            //COLUMN
            if (somersaults == 0.5)
                column = 0;
            else if (somersaults == 1)
                column = 1;
            else if (somersaults == 1.5)
                column = 2;
            else if (somersaults == 2)
                column = 3;
            else if (somersaults == 2.5)
                column = 4;
            else if (somersaults == 3)
                column = 5;
            else if (somersaults == 3.5)
                column = 6;
            else if (somersaults == 4)
                column = 7;
            else if (somersaults == 4.5)
                column = 8;
            else if (somersaults == 5.5)
                column = 9;


            if ((height == 1 || height == 3) && column < 9)
                return tableEfor1and3[row, column];
            else if (height == 5 || height == 7.5 || height == 10)
                return tableEfor5and7and10[row, column];
            else
                return -10;
        }
        #endregion Calculation parts
    }

}